<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <button @click="show=!show">toggle</button>
        <test v-if="show"></test>
    </div>
    <script>
        Vue.component("test",{
            template:"<div class='test'>xxxxxxxxx</div>",
            //创建
            created:function(){
                console.log("创建之后",this,document.querySelector(".test"));
            },
            //挂载DOM
            mounted:function(){
                console.log("挂载之后",this,document.querySelector(".test"));
            },
            //销毁
            destroyed:function(){
                console.log("销毁之后");
            },
        });
        var vm=new Vue({
            el:"#app",
            data:{
               show:true
            },
        
        });
       
        
    </script>
</body>
</html>